package sg.nus.iss.vmcs.controllers;

import sg.nus.iss.vmcs.utils.Password;

/**
 * Access Manager used for verifying passwords and managing passwords UI elements
 * @author Pang Pingli
 */
public class AccessManager {
	
	/** Maintenance Controller, parent controller */
    private MaintenanceController   mctrl;
    
    /** Checks if Maintainer is logged in */
    private boolean loginState = false;

    /**
     * Creates an instance of Access Manager
     * @param mc
     */
    public AccessManager (MaintenanceController mc) {
    	mctrl = mc;
    }

    /**
     * Processes the validity of a password using the Password utility
     * @param ps Maintainer entered password
     */
    public void processPassword(String ps) {
	    loginState = Password.validatePassword(ps);
	    mctrl.loginMaintainer(loginState);
    }

    /**
     * Gets the current login state of the system
     * @return Current login state
     */
    public boolean getLoginState(){
    	return loginState;
    }

    /**
     * Logs out a maintainer, setting it to log out
     */
    public void logout(){
    	loginState = false;
    }
}